package top.moonkit.rs_pro.patterns.login;

import cn.hutool.crypto.digest.BCrypt;
import org.springframework.stereotype.Service;
import top.moonkit.rs_pro.entity.User;
import top.moonkit.rs_pro.entity.vo.LoginRequestVO;
import top.moonkit.rs_pro.exception.BusinessException;
import top.moonkit.rs_pro.utils.Mu;

/**
 * @author moon
 * @since 0.0.1
 */
@Service
public class EMailPasswordLoginProcessor  implements LoginProcessorService{


    @Override
    public boolean isMe(String account, Boolean isPassword) {
        return (isPassword && account.contains("@"));
    }

    @Override
    public void verifyAccount(LoginRequestVO vo, User user) {
        if (!BCrypt.checkpw(vo.getPassword(), user.getPassword())){
            throw new BusinessException(Mu.m("login.password_error"));
        }
    }

}
